package org.jiajie.coffeecodes.concurrent.pool;

import cn.hutool.http.HttpUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author jie
 */
public class RequestThreadPool {
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 10; i++) {
            es.submit(new Task("" + i));
        }
        // 关闭线程池
        es.shutdown();
    }
}

class Task implements Runnable {
    private final String name;

    Task(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println("start task " + name);
        String param = "{\n" +
                "    \"appId\":\"wxa736a54d6a712435\",\n" +
                "    \"openId\":\"oOWe45Tn8fYn345tdcbFJsh2pXE7\",\n" +
                "    \"unionId\":\"o2dOq1U7PShuCmh7urGdeB0eAXR7\",\n" +
                "    \"nickName\":\"test01010\",\n" +
                "    \"headImageUrl\":\"https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoGPrSrSNJYma1pS7m0yUEiaIWnGqkzYqnBgAbEmjhda31OYWzRRkHAUTquYUkJqz3KXx2c2cPKGVg/132\",\n" +
                "    \"mobile\":\"\",\n" +
                "    \"gender\":\"\",\n" +
                "    \"nakedSystem\":\"LOTTERY\" \n" +
                "}";
        String result = HttpUtil.post("http://localhost:18008/evoucher/cms/member/collect", param);
//        System.out.println(result);
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("end task " + name + "-" + result);
    }
}
